#! /usr/bin/python

import math
UP = 10**6

def isPrime(n):
    if n==2 or n==3 or n==5 or n==7: return True
    if n%2 == 0 or n%3 == 0 or n ==1: return False
    for i in range(5, int(math.sqrt(n) + 1), 6):
	if n%i == 0 or n%(i+2) == 0: return False
    return True

count = 0
for a in range(1, UP+1):
    p = 3*a**2 + 3*a + 1
    if p > UP: break
    if isPrime(p):       
       count += 1
       print p, a	
print count 
